home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Dates
/
DateObject.cp
next >
Wrap
Text File
|
1997-06-28
|
2KB
|
102 lines
// DateObject.cp
#ifndef DateObject_h
#include "DateObject.h"
#endif
Handle DateObject::Intl0Resource()
{
static Handle resource = GetIntlResource( 0 );
return resource;
}
Handle DateObject::Intl1Resource()
{
static Handle resource = GetIntlResource( 1 );
return resource;
}
DateCacheRecord *DateObject::MakeCache()
{
static DateCacheRecord cache;
InitDateCache( &cache );
return &cache;
}
DateCacheRecord *DateObject::Cache()
{
static DateCacheRecord *cache( MakeCache() );
return cache;
}
DateObject DateObject::Now()
{
uint32 now;
GetDateTime( &now );
return now;
}
void DateObject::operator=( ConstData text )
{
LongDateRec date;
int32 used;
StringToDateStatus result = StringToDate( (Ptr)text.Start(),
text.Length(),
Cache(),
&used,
&date );
const StringToDateStatus okResults = longDateFound | leftOverChars;
Assert( used > 0 );
Assert( ( result & ~okResults ) == 0 );
text.Shorten( used );
if ( !text.IsEmpty() )
{
result = StringToTime( (Ptr)text.Start(),
text.Length(),
Cache(),
&used,
&date );
Assert( used == text.Length() );
Assert( result == noErr );
}
LongDateTime time;
LongDateToSeconds( &date, &time );
secondsFrom1904 = time.lo;
}
void DateObject::WriteDate( String255& string ) const
{
LongDateTime time;
time.hi = secondsFrom1904 >> 32;
time.lo = secondsFrom1904;
LongDateString( &time, longDate, string, Intl1Resource() );
}
void DateObject::WriteTime( String255& string ) const
{
LongDateTime time;
time.hi = secondsFrom1904 >> 32;
time.lo = secondsFrom1904;
LongTimeString( &time, true, string, Intl0Resource() );
}
void DateObject::WriteDateAndTime( String255& string ) const
{
WriteDate( string );
String255 timeString;
WriteTime( timeString );
string += "\p ";
string += timeString;
}